package library.operation;

import library.Book;
import library.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{//还书
    @Override
    public void work(BookList bookList) {
        System.out.println("还书操作");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书籍编号");
        int id = scanner.nextInt();
        if (id < 0 || id >= bookList.getSize()) {//判断输入的编号是否有效
            System.out.println("输入的编号超出范围");
            return;
        }
        //获取书籍
        Book book = bookList.getBook(id);
        //判断书籍是否被借出
        if (book.isBorrowed() == false) {
            System.out.println("该书籍未被借出,无法归还");
            return;
        } else {
            book.setBorrowed(false);
            System.out.println("归还成功");
        }
    }
}
